/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package stacksassignement1;

import java.util.Stack;
import javax.swing.JOptionPane;

public class IntStack {
    private int   stackSize;
    private int   stackPointer;
    private int[] element;
    IntStack(int size){
        stackSize = size;
        element = new int [stackSize];
        stackPointer = -1;
    }

    public boolean searchStack(int item){
        //int x = stackPointer;
        while (stackPointer >= 0) {
            if (item == element[stackPointer]) {
                return true;
            }
            else {
                stackPointer = stackPointer - 1;
            }
        }
        return false;
    }



    
    public int getStackSize(){
    return stackSize;
}
        
    public boolean isEmpty(){
        return(getStackPointer()==-1); //returns true if stackpointer is equal to -1
}
    
    public boolean isFull(){
        return(getStackPointer()==getStackSize()-1); //returns true if stackpointer is the same as stacksize -1
    }
    
   
    public int pop() throws StackException{
        if(isEmpty())
            throw new StackException("Stack Is Empty");
        else 
            return getElement()[stackPointer--];
    }
    
    public void push(int newElement) throws StackException{
        if(isFull())
            throw new StackException("Stack Is Full");
        else 
            getElement()[++stackPointer] = newElement;
    }

   
    public void setStackSize(int stackSize) {
        this.stackSize = stackSize;
    }

  
    public int getStackPointer() {
        return stackPointer;
    }

    
    public void setStackPointer(int stackPointer) {
        this.stackPointer = stackPointer;
    }

    /**
     * @return the element
     */
    public int[] getElement() {
        return element;
    }

    /**
     * @param element the element to set
     */
    public void setElement(int[] element) {
        this.element = element;
    }

    public String printToScreen(int[] stack){
        String output="";
        for(int i =0; i<10;i++){
         output+=stack[i]+" ";
        }
        output+="\n";
        return output;
    }
}          
    

